package com.qf.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.elasticsearch.annotations.*;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.*;

@Data
@Accessors(chain = true)
@Document(indexName = "hotal_index", shards = 1, replicas = 0)
public class Hotal implements Serializable {

  @TableId(type = IdType.AUTO)
  @Id
  private Integer id;
  @MultiField(
          mainField = @Field(type = FieldType.Text, analyzer = "ik_max_word"),
          otherFields = @InnerField(type = FieldType.Text, analyzer = "pinyin", suffix = "pinyin")
  )
  private String hotalName;
  @Field(type = FieldType.Keyword, index = false)
  private String hotalImage;
  @Field(type = FieldType.Integer)
  private Integer type;
  @MultiField(
          mainField = @Field(type = FieldType.Text, analyzer = "ik_max_word"),
          otherFields = @InnerField(type = FieldType.Text, analyzer = "pinyin", suffix = "pinyin")
  )
  private String hotalInfo;
  @MultiField(
          mainField = @Field(type = FieldType.Text, analyzer = "ik_max_word"),
          otherFields = {
                  @InnerField(type = FieldType.Text, analyzer = "pinyin", suffix = "pinyin"),
                  @InnerField(type = FieldType.Keyword, suffix = "keyword")
          }
  )
  private String keyword;

  @Transient
  private double lon;
  @Transient
  private double lat;

  /**
   * 经纬度坐标
   */
  @GeoPointField
  @TableField(exist = false)
  private Double[] location = new Double[2];

  @Field(type = FieldType.Integer)
  private Integer star;

  @MultiField(
          mainField = @Field(type = FieldType.Text, analyzer = "ik_max_word"),
          otherFields = @InnerField(type = FieldType.Text, analyzer = "pinyin", suffix = "pinyin")
  )
  private String brand;

  @MultiField(
          mainField = @Field(type = FieldType.Text, analyzer = "ik_max_word"),
          otherFields = @InnerField(type = FieldType.Text, analyzer = "pinyin", suffix = "pinyin")
  )
  private String address;

  @DateTimeFormat(pattern = "yyyy-MM-dd")
  @Field(type = FieldType.Long)
  private Date openTime;

  @Transient
  private Integer cid;
  @MultiField(
          mainField = @Field(type = FieldType.Text, analyzer = "ik_max_word"),
          otherFields = @InnerField(type = FieldType.Text, analyzer = "pinyin", suffix = "pinyin")
  )
  private String reg;


  /**
   * 嵌套类型
   */
  @Field(type = FieldType.Nested)
  @TableField(exist = false)
  private City city = new City();

  /**
   * 嵌套类型 - 客房类型
   */
  @Field(type = FieldType.Nested)
  @TableField(exist = false)
  private List<Room> rooms = new ArrayList<>();


  @ScriptedField
  @TableField(exist = false)
  private double avgPrice;

  @ScriptedField
  @TableField(exist = false)
  private double distance;

  @Field(type = FieldType.Long)
  @TableField(exist = false)
  private long djl = 0;


  public Hotal setLon(double lon) {
    this.lon = lon;
    location[0] = lon;
    return this;
  }

  public Hotal setLat(double lat) {
    this.lat = lat;
    location[1] = lat;
    return this;
  }
}
